const def = ['common', 'dataSource', 'socket', 'ajax'];
define(def, function(Common, dataSource, socket, ajax) {
    const util = Common.util;
    const { routes, menus } = dataSource;
    const Menu = util.Class(Common);

    console.log('common', util);

    Menu.include({
        /**
         * 初始化 获取顶部菜单
         */
        initMenus() {
            ajax.getMenus().then(menuData => {
                const menuList = ['<li class="cm-menu-item" data-href="home"><span>首页</span></li>'];
                const menuSource = menuData.menuItem;

                // 默认有一个，表示首页
                for (i = 0; i < menuSource.length; i++) {
                    const menuItem = menuSource[i].menuItem;
                    const subMenu = [];
                    for(let j = 0, length = menuItem.length; j < length; j++) {
                        const submenu = menuItem[j];
                        const href = menus[submenu.menuName];

                        if (href) {
                            subMenu.push(
                                `<li class="cm-submenu-item" data-href="${href}">
                                    ${submenu.menuName.substring(0,6)}
                                </li>`
                            )
                        }
                    }

                    menuList.push(
                        `<li class="cm-menu-item">
                            <span>${menuSource[i].menuName}</span>
                            <ul class="cm-submenu">
                                ${subMenu.join('')}
                            </ul>
                        </li>`
                    );
                }
                $('#cmMenu').html(menuList);
                // this.bindMenuEvent();
            });
        },
        bindMenuEvent () {

        },
    });

    return new Menu();
});
